package com.sondon.mayi.adapter;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sondon.mayi.entity.MyVoucher;
import com.sondon.mayi.events.CheckboxEvent;
import com.sondon.mayi.fruit.R;
import com.sondon.mayi.util.PreferencesUtil;

import de.greenrobot.event.EventBus;

/**
 * @Project : Fruit
 * @Package : com.sondon.mayi.adapter
 * @Class : MyVoucherList_Item
 * @Author : 蔡文锋
 * @DateTime：2015年6月29日 下午9:31:09
 * @Blog：http://blog.csdn.net/caiwenfeng_for_23
 * @Description : { 代金劵 }
 *
 */
@EViewGroup(R.layout.myvoucherlist_item)
public class MyVoucherList_Item extends LinearLayout {
	private Context context;
	private int position;
	@ViewById
	TextView myvoucher_list_img;//代金劵图片
	@ViewById
	TextView myvoucher_list_yuan;//代金劵金额
	@ViewById
	TextView myvoucher_list_time;//代金劵有效期
	@ViewById
	CheckBox myvoucher_item_checkbox;//选择框
	
	public MyVoucherList_Item(Context context) {
		super(context);
		this.context=context;
	}
	
	public void bindData(MyVoucher myVoucher,int position){
		this.position=position;
		String value=myVoucher.getValue();
		myvoucher_list_img.setText(value.subSequence(0, value.indexOf("."))+"元");
		myvoucher_list_yuan.setText("代金劵 "+value+" 元");
		myvoucher_list_time.setText("有效期 :"+myVoucher.getEnd_time());
		
		boolean is_forResult=PreferencesUtil.getBooleanValue("is_forResult");
		
		if(is_forResult){
			myvoucher_item_checkbox.setVisibility(View.VISIBLE);
		}else{
			myvoucher_item_checkbox.setVisibility(View.GONE);
		}
	}
	
	
	@Click({R.id.myvoucher_item_checkbox})
	public void onClick(View v){
		switch (v.getId()) {
		case R.id.myvoucher_item_checkbox:
			EventBus.getDefault().post(new CheckboxEvent(this.position));
			break;

		default:
			break;
		}
	}
	
}
